<?php
namespace ImiApp\ApiServer\Controller;

use Imi\Controller\HttpController;
use Imi\Server\Route\Annotation\Action;
use ImiApp\ApiServer\Model\RedisTestModel;
use Imi\Server\Route\Annotation\Controller;

/**
 * @Controller("/redisModel/")
 */
class RedisModelController extends HttpController
{
    /**
     * 写入
     * 
     * @Action
     *
     * @param string $key
     * @param string $value
     * @return void
     */
    public function set(string $key, string $value)
    {
        $model = RedisTestModel::newInstance();
        $model->setName($value);
        $model->setKey($key);
        $model->save();
    }


    /**
     * 取出
     * 
     * @Action
     *
     * @param string $key
     * @return void
     */
    public function get(string $key)
    {
        $model = RedisTestModel::find($key);
        return [
            'data1'  =>  $model->name,
            'data2'  =>  $model->getName(),
        ];
    }

    /**
     * 删除
     * 
     * @Action
     *
     * @param string $key
     * @return void
     */
    public function delete(string $key)
    {
        $model = RedisTestModel::find($key);
        $model->delete();
    }

}
